package com.gccloud.design;

import com.gccloud.design.dto.SearchMyBusiness;
import com.gccloud.design.dto.UcBusiShowDto;
import com.gccloud.design.dto.UserAndRoleBusiOrderConfigDto;
import com.gccloud.design.entity.SdFormDefineEntity;
import com.gccloud.design.entity.UcBusiShowEntity;
import com.gccloud.design.service.UcBusiOrderShowService;
import com.gccloud.design.vo.SequenceVo;
import com.gccloud.design.vo.UserAndRoleBusiOrderConfigVo;
import com.gccloud.starter.common.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiSort;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 用户业务场景展示
 *
 * @author guo.wang
 */
@RestController
@RequestMapping("/ucBusiOrderShow")
@Api(tags = "用户业务场景展示")
@ApiSort(value = 13)
public class UcBusiOrderShowController {

    @Resource
    private UcBusiOrderShowService ucBusiOrderShowService;

    @RequestMapping(value = "/userAndRoleBusiOrderConfig", method = RequestMethod.POST)
    @ApiOperation(value = "配置用户与角色场景展示权限")
    public R<Boolean> userAndRoleBusiOrderConfig(@RequestBody UserAndRoleBusiOrderConfigDto userAndRoleBusiOrderConfigDto) {
        Boolean result = ucBusiOrderShowService.userAndRoleBusiOrderConfig(userAndRoleBusiOrderConfigDto);
        return R.success(result);
    }

    @RequestMapping(value = "/findUserAndRoleOrderConfig", method = RequestMethod.POST)
    @ApiOperation(value = "查询角色和人员业务场景配置")
    public R<UserAndRoleBusiOrderConfigVo> findUserAndRoleOrderConfig(@RequestBody String[] formIds) {
        UserAndRoleBusiOrderConfigVo result = ucBusiOrderShowService.findUserAndRoleOrderConfig(formIds);
        return R.success(result);
    }

    @RequestMapping(value = "/getMyOrderList", method = RequestMethod.POST)
    @ApiOperation(value = "获取我的业务场景单")
    public R<List<UcBusiShowEntity>> getMyOrderList(@RequestBody SearchMyBusiness searchMyBusiness) {
        List<UcBusiShowEntity> result = ucBusiOrderShowService.getMyOrderList(searchMyBusiness);
        return R.success(result);
    }

    @RequestMapping(value = "/getMyOrderListByIds", method = RequestMethod.GET)
    @ApiOperation(value = "根据orderTyIds获取我的业务场景单")
    public R<List<UcBusiShowEntity>> getMyOrderListByIds(@RequestParam Map<String, String> map) {
        List<UcBusiShowEntity> result = ucBusiOrderShowService.getMyOrderListByIds(map);
        return R.success(result);
    }

    @ApiOperation(value = "获取我的业务场景单菜单")
    @GetMapping("/getBusiTree")
    public R<List<UcBusiShowDto>> getBusiTree(@RequestParam Map<String, String> map) {
        List<UcBusiShowDto> list = ucBusiOrderShowService.getBusiTree(map);
        return R.success(list);
    }


    @RequestMapping(value = "/updateMyOrder", method = RequestMethod.POST)
    @ApiOperation(value = "修改我的业务场景")
    public R<Boolean> updateMyOrder(@RequestBody UcBusiShowEntity ucBusiShowEntity) {
        Boolean result = ucBusiOrderShowService.updateMyOrder(ucBusiShowEntity);
        return R.success(result);
    }

    @RequestMapping(value = "/updateMyOrderSequence", method = RequestMethod.POST)
    @ApiOperation(value = "修改我的业务场景顺序")
    public R<Boolean> updateMyOrderSequence(@RequestBody List<UcBusiShowEntity> ucBusiShowEntity) {
        Boolean result = ucBusiOrderShowService.updateMyOrderSequence(ucBusiShowEntity);
        return R.success(result);
    }

    @RequestMapping(value = "/updateMyOrderByFormId", method = RequestMethod.POST)
    @ApiOperation(value = "根据formId修改业务场景")
    public R<Boolean> updateMyOrderByFormId(@RequestBody UcBusiShowEntity ucBusiShowEntity) {
        Boolean result = ucBusiOrderShowService.updateMyOrderByFormId(ucBusiShowEntity);
        return R.success(result);
    }

    @RequestMapping(value = "/getMyOrderByFormId", method = RequestMethod.POST)
    @ApiOperation(value = "根据formId查询业务场景")
    public R<List<UcBusiShowEntity>> getMyOrderByFormId(@RequestBody UcBusiShowEntity ucBusiShowEntity) {
        List<UcBusiShowEntity> result = ucBusiOrderShowService.getMyOrderByFormId(ucBusiShowEntity);
        return R.success(result);
    }

    @RequestMapping(value = "/delMyOrderByFormId", method = RequestMethod.POST)
    @ApiOperation(value = "根据formId删除业务场景人员")
    public R<Boolean> delMyOrderByFormId(@RequestBody UserAndRoleBusiOrderConfigDto userAndRoleBusiOrderConfigDto) {
        Boolean result = ucBusiOrderShowService.delMyOrderByFormId(userAndRoleBusiOrderConfigDto);
        return R.success(result);
    }

    @RequestMapping(value = "/delByFormId/{formId}", method = RequestMethod.POST)
    @ApiOperation(value = "根据formId删除业务场景人员配置")
    public R<Integer> delByFormId(@PathVariable("formId") Long[] formIds) {
        int result = ucBusiOrderShowService.delByFormId(formIds);
        return R.success(result);
    }

    @RequestMapping(value = "/getFormUrlByFormId", method = RequestMethod.GET)
    @ApiOperation(value = "基于formid得到formUrl")
    public R<SdFormDefineEntity> getFormUrlByFormId(Long formId) {
        SdFormDefineEntity sdFormDefineEntity = ucBusiOrderShowService.getFormUrlByFormId(formId);
        return R.success(sdFormDefineEntity);
    }

    @PostMapping(value = "/changeSequence")
    @ApiOperation(value = "拖拽图标改变排序")
    public R<Long> changeSequence(@RequestBody List<SequenceVo> sequenceVos) {
        return R.success(ucBusiOrderShowService.changeSequence(sequenceVos));
    }
}
